<template>
  <view>
    <!-- parse <include src="../component/navigationBar.wxml"></include> -->
    <block>
      <view
          :style="'padding-top:' + nTop + 'px;height:' + nHeight + 'px;line-height:' + nHeight + 'px;--color:' + color + ';'"
          class="navigationBox">
        <view :style="'height:' + nHeight + 'px;top:' + nTop + 'px'" class="nBar">
          <navigator :openType="pages.length == 1 ? 'switchTab' : 'navigateBack'"
                     :url="pages.length == 1 ? '/pages/index/index4' : ''" class="ico"
                     hoverClass="none">
            {{ pages.length == 1 ? '' : '' }}
          </navigator>
          <view class="title">{{ nTitle }}</view>
        </view>
      </view>
    </block>
    <scroll-view
        :enableBackToTop="true"
        :enableFlex="true"
        :refresherEnabled="true"
        :refresherTriggered="triggered"
        :scrollTop="scrolltopNum_index"
        :scrollWithAnimation="true"
        :scrollY="true"
        :style="'margin-top:' + nTH + 'px;height:-webkit-calc(100vh - ' + nTH + 'px);--color:' + color + ';--rgbcolor:' + rgbcolor"
        lowerThreshold="50"
        @refresherrefresh="onPullDownRefresh"
    >
      <view v-if="t == 'flag0'" class="BOX flag0">
        <view :style="'color:' + color" class="ico bigico"></view>
        <view class="h4">{{ TGU.nickname_str }}</view>
        <view v-if="!globalUtils.empty(TGU.nickname_str2)" class="h4">{{ TGU.nickname_str2 }}</view>
        <navigator class="btn5" hoverClass="none" openType="reLaunch" url="index">进入{{
            TGU.gradetitle
          }}首页
        </navigator>
        <navigator :style="'--color:' + color + ';--rgbcolor:' + rgbcolor" class="btmKefuBtn loop_s_b_s"
                   url="/pagesA/about/about">
          <view class="i ico"></view>
          客服
        </navigator>
      </view>
      <view v-else-if="t == 'flag_1'" class="BOX flag_1">
        <view class="ico bigico" style="color: #999"></view>
        <view class="h4">{{ TGU.nickname_str }}</view>
        <navigator class="btn5" hoverClass="none" openType="reLaunch" url="index">进入{{
            TGU.gradetitle
          }}首页
        </navigator>
        <navigator :style="'--color:' + color + ';--rgbcolor:' + rgbcolor" class="btmKefuBtn loop_s_b_s"
                   url="/pagesA/about/about">
          <view class="i ico"></view>
          客服
        </navigator>
      </view>
      <view v-else-if="t == 'flag2'" class="BOX HELP">
        <view class="ico bigico" style="color: #ff6a00"></view>
        <view class="B">激活帐号</view>
        <view class="h4">{{ TGU.nickname_str }}</view>
        <view v-if="TGU.active_price > 0" class="h4">
          请支付
          <text>¥{{ TGU.active_price }}</text>
          元激活，成为【{{ TGU.gradetitle }}】
        </view>
        <button v-if="TGU.active_price > 0" class="btn5" @tap="payFn">立即支付（¥{{ TGU.active_price }}）</button>
        <button v-else class="btn5" @tap="payFn">开始激活</button>
        <view class="h1">{{ HELP.h1 }}</view>
        <view class="c">
          <rich-text :nodes="HELP.c1"></rich-text>
        </view>
        <navigator :style="'--color:' + color + ';--rgbcolor:' + rgbcolor" class="btmKefuBtn loop_s_b_s"
                   url="/pagesA/about/about">
          <view class="i ico"></view>
          客服
        </navigator>
      </view>
      <view v-else class="BOX HELP">
        <view v-if="flag !== '0'" class="reg">
          <view class="h1">{{ h1 }}</view>
          <view class="h5">{{ h5 }}</view>
          <navigator v-if="!globalUtils.empty(btn_u)" :url="'/pages/login/login?admid=' + admid + '&tguid=' + tguid"
                     class="btn5 ed"
                     hoverClass="none">{{ btn_u }}
          </navigator>
          <navigator v-if="!globalUtils.empty(btn_u)" :url="'/hnPages/tg/login?admid=' + admid + '&tguid=' + tguid"
                     class="btn5"
                     hoverClass="none">{{ btn_tg }}
          </navigator>
        </view>
      </view>
      <view class="blank">　</view>
    </scroll-view>
    <privacy-popup @agree="privacy_agree" @disagree="privacy_disagree"></privacy-popup>
  </view>
</template>
<script>
import privacyPopup from '../../components/privacyPopup/privacyPopup.vue';
import globalUtils from "../../res/www.a9a.cn";

var t = require('../../res/www.a9a.cn.js');
var app = getApp();
var a = uni.getStorageSync('COOK_U');
export default {
  computed: {
    globalUtils() {
      return globalUtils
    }
  },
  components: {
    privacyPopup
  },
  data() {
    return {
      nTitle: '',
      triggered: true,
      color: '',
      rgbcolor: '',
      t: '',
      tguid: '',
      admid: '',
      TGU: {
        nickname_str: '',
        nickname_str2: '',
        gradetitle: '',
        active_price: 0
      },
      MB: '',
      HELP: {
        h1: '',
        c1: ''
      },
      flag: '',
      h1: '',
      h5: '',
      btn_u: '',
      btn_tg: '',
      nTop: '',
      nHeight: '',
      pages: [],
      scrolltopNum_index: 0,
      nTH: ''
    };
  },
  onLoad: function (a) {
    uni.showNavigationBarLoading();
    var that = this;
    var n = 0;
    var o = 0;
    app.globalData.get_config('_ZEAI').then(function (a) {
      that.setData({
        color: app.globalData._ZEAI.color,
        rgbcolor: t.c16_rgb(app.globalData._ZEAI.color)
      });
    });
    var r = a.t;
    r = app.globalData.empty(r) ? '' : r;
    if (t.ifint(a.tguid) || t.ifint(a.admid)) {
      n = t.ifint(a.tguid) ? a.tguid : 0;
      o = t.ifint(a.admid) ? a.admid : 0;
      console.log()
    } else {
      for (var s = decodeURIComponent(a.scene), g = {}, l = 0; l < s.split('*').length; l++) {
        var c = s.split('*')[l].split('/');
        g[c[0]] = c[1];
      }
      o = t.ifint(g.a) ? g.a : 0;
      n = t.ifint(g.t) ? g.t : 0;
      r = '';
    }
    app.globalData.get_navigationBarTopHeight(that);
    app.globalData.get_openid().then(function (t) {
      that.init();
    });
    that.setData({
      t: r,
      tguid: n,
      admid: o
    });
    console.log('reg->  tguid=' + n);
    console.log('reg->  admid=' + o);
  },
  onPullDownRefresh: function () {
    var that = this;
    uni.vibrateShort({
      type: 'heavy'
    });
    setTimeout(function () {
      that.setData({
        triggered: false
      });
      that.init();
    }, 500);
  },
  onShareAppMessage: function () {
    return {
      imageUrl: this.loading.share.imgurl,
      title: this.loading.share.title,
      path: '/hnPages/tg/reg'
    };
  },
  onShareTimeline: function () {
    return {
      imageUrl: this.loading.share.imgurl,
      title: this.loading.share.title,
      query: '',
      path: '/hnPages/tg/reg'
    };
  },
  methods: {
    init: function () {
      var that = this;
      a = uni.getStorageSync('COOK_U');
      uni.showNavigationBarLoading();
      uni.showLoading({
        title: '玩命加载中',
        mask: true
      });
      app.globalData.ajax({
        url: 'tg.php',
        data: {
          submitok: 'reg',
          openid: a.openid
        },
        success: function (a) {
          uni.setNavigationBarTitle({
            title: a.nTitle
          });
          uni.hideNavigationBarLoading();
          uni.hideLoading();
          that.flag = a.flag;
          if (1 == a.flag) {
            'flag1' == a.t
                ? uni.redirectTo({
                  url: '/hnPages/tg/my'
                })
                : that.setData({
                  nTitle: a.nTitle,
                  TGU: a.TGU,
                  t: a.t,
                  MB: a.MB,
                  HELP: a.D
                });
          } else {
            if (0 == a.flag) {
              a.this = that;
              a.url = 'no';
              t.sorry(a);
              return void that.setData({
                flag: a.flag
              });
            }
            app.globalData.empty(a.t)
                ? that.setData({
                  nTitle: a.nTitle,
                  h1: a.h1,
                  h5: a.h5,
                  btn_u: a.btn_u,
                  btn_tg: a.btn_tg
                })
                : ((a.this = that), (a.url = 'no'), t.sorry(a));
          }
        }
      });
    },

    payFn: function () {
      var that = this;
      t.empty(that.MB) || app.globalData.openSetting(that.MB);
      a = uni.getStorageSync('COOK_U');
      uni.showLoading({
        title: '玩命加载中',
        mask: true
      });
      app.globalData.ajax({
        url: 'tg.php',
        data: {
          submitok: 'reg_pay_active',
          openid: a.openid
        },
        success: function (n) {
          uni.hideLoading();
          1 == n.flag
              ? uni.showModal({
                content: n.msg,
                confirmColor: that.color,
                confirmText: '朕知道了',
                showCancel: false,
                success: function (t) {
                  uni.reLaunch({
                    url: 'my'
                  });
                }
              })
              : 'pay' == n.flag
                  ? app.globalData.pay({
                    data: {
                      submitok: 'tg_pay_active',
                      openid: a.openid
                    },
                    success: function (i) {
                      1 == i.flag
                          ? uni.showModal({
                            content: '激活成功！',
                            confirmColor: that.color,
                            confirmText: '朕知道了',
                            showCancel: false,
                            success: function (t) {
                              uni.reLaunch({
                                url: 'my'
                              });
                            }
                          })
                          : ((n.this = that), (n.url = 'no'), t.sorry(n));
                    },
                    fail: function (i) {
                      i.this = that;
                      i.url = 'no';
                      t.sorry(i);
                    }
                  })
                  : ((n.this = that), (n.url = 'no'), t.sorry(n));
        }
      });
    },

    privacy_agree: function (t) {
    },

    privacy_disagree: function (t) {
      console.log('disagree');
      uni.exitMiniProgram();
    },

    onPullDownRefresh() {
      console.log('占位：函数 onPullDownRefresh 未声明');
    }
  }
};
</script>
<style>
@import 'reg.css';
</style>
